package com.twu.biblioteca.view;


import com.twu.biblioteca.controller.UserController;
import com.twu.biblioteca.models.Library;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: ema93sh
 * Date: 8/8/13
 * Time: 8:09 PM
 */
public class BibliotecaUI {
    private Library library;
    private List<MenuItem> menuItemList;
    private UserController userController;

    public BibliotecaUI(Library library, UserController userController)
    {
        this.library = library;
        this.userController = userController;
        menuItemList = new ArrayList<MenuItem>();
        setupMainMenu();
    }


    public void displayWelcomeMessage() {
        System.out.println("Welcome to Biblioteca\n");
    }

    public void setupMainMenu() {
        menuItemList.add(new BookView(library));
        menuItemList.add(new MovieView(library));
        menuItemList.add(new ReserveView(library, userController));
        menuItemList.add(new MembershipView(userController));
        menuItemList.add(new LoginView(userController));
        menuItemList.add(new ExitView());
    }

    public void selectMenuItem(int choice) throws IOException {
        if (choice > 0 && choice <= menuItemList.size())
        {
            MenuItem item = menuItemList.get(choice-1);
            item.doWork();
        }
        else
        {
            System.out.println("Select a valid option!!");
        }
    }

    public void displayMainMenu() {
        int menuNumber = 1;
        System.out.println("Main Menu:");

        for (MenuItem item : menuItemList)
        {
           System.out.println(menuNumber + ". " + item.displayTitle());
           menuNumber++;
        }
        System.out.println("Enter your choice:");
    }
}
